#!/bin/bash


#    / **  
#    *〈 判断文件夹是否存在，不存在则，建立链接，存在则备份并建立链接 〉  
#    *〈功能详细描述〉  
#    * @param [参数1] [文件路径]  
#    * @param [参数2] [链接建立命令]  
#    * @return [返回类型说明]  
#    * @exception/throws [违例类型] [违例说明]  
#    * @see [类、类#方法、类#成员]  
#    * @deprecated  
#    * 例子：
#    *      判断文件夹 ~/.vim是否存在，不存在则执行命令，存在则备份后执行命令 
#    *      folderPath=${HOME}"/.vim"
#    *      echo "[Debug] folderPath= ${folderPath}"
#    *      commandStr="mkdir -p ${folderPath}"
#    *      echo "[Debug] commandStr=${commandStr}"
#    *      bakAndLinkFolder ${folderPath} "${commandStr}"
#    *      # 注：参数中带有空格，如果直接写的话，会从空格处自动切分开。解决方法：将这个引用变量用双引号括起来
#    */  
function bakAndMakeFolderLink()
{
    echo "[Debug]: bakAndLinkFolder !";
    # folderPath=${HOME}"/.vim"
    originFolderPath=$1;
    targetFolderPath=$2;
    commandStr=$3;
    echo "[INFO]: originFolderPath=${originFolderPath}";
    echo "[INFO]: targetFolderPath=${targetFolderPath}";
    echo "[INFO]: commandStr=${commandStr}";

    # 判断是文件夹/文件夹软链接是否已经存在
    if [[ "$(readlink ${targetFolderPath})" = "${originFolderPath}" ]]; then
       #echo "[INFO]: 文件夹软链接已经存在 ";
       success "${targetFolderPath} ==>${originFolderPath} 文件夹软链接已经存在"
    else
        if [ -L "$targetFolderPath" ] || [ -d "$targetFolderPath" ] ; then
            echo "[INFO] 备份文件夹/文件夹软链接 ${targetFolderPath}";
            cmdStr="mv ${targetFolderPath} ${targetFolderPath}-`date +%y%m%d%H%M%S`";
            echo "执行命令: ${cmdStr}";
            ${cmdStr}
        fi
        echo "[INFO]: 创建文件夹软链接";
        cmdStr="ln -s  ${originFolderPath}  ${targetFolderPath}"
        echo "执行命令: ${cmdStr}";
        ${cmdStr}

        # 执行命令
        echo "执行命令: ${commandStr}";
        ${commandStr}
    fi
}


#    / **  
#    *〈流程控制〉  
#    *〈该脚本的主函数〉  
#    * @param [无]  
#    * @return [无]  
#    * @exception/throws [无]  
#    * @deprecated  
#    */  
function processControlMain()  
{  
    # 打印当前系统时间  
    echo "Start..."  
    date  

    # 此处是你的代码  
    # ...  
    ## font

    # Make link
    ## 获取当前脚本目录位置
        # 获取当前脚本目录位置
        dir=`pwd`
        echo "获取当前脚本目录位置:"${dir}
    ## 配置文件
    # bakAndMakeFolderLink "${dir}/" "${HOME}/.config/yabai"

    # 安装 包管理软件 
    # brew
    # 国内自动安装 Homebrew 的脚本
    #/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

    # rust的包管理器 cargo
    # brew install rust cargo
    ### - 终端复用器
    #cargo install zellij

    ## 常用软件
    ### - 版本管理器
    brew install git

    ### - 终端复用器
    brew install tmux
    brew install zellij # 基于rust的终端窗口管理（如：tmux ）

    ### - lsd
    brew install lsd

    ### - 编辑器
    brew install vim 
    brew install neovim
    # brew install helix # 基于rust的编辑器

    ### - 终端文件管理
    brew install ranger 
    brew install lf

    brew install lazygit
    # brew install lazynpm
    brew install jesseduffield/lazynpm/lazynpm
    # go install github.com/jesseduffield/lazynpm@latest
    brew install tig
    brew install lazydocker

    ## kitty 扩展需要
    brew install bat
    brew install imagemagick

    ## 字体
    # brew tap homebrew/cask-fonts
    # brew install font-inconsolata
    # brew install font-fira-code-nerd-font
    brew install font-jetbrains-mono

    ## 窗口管理器
    # brew install koekeishiya/formulae/yabai
    # brew install koekeishiya/formulae/skhd
    # brew install hammerspoon
    # brew install cmacrae/formulae/spacebar
    # brew install jq


    brew install fswatch            # [macos - Mac 上是否有类似“watch”或“inotifywait”的命令？_Stack Overflow中文网](https://stackoverflow.org.cn/questions/1515730)
    brew install terminal-notifier  # [terminal-notifier: 从命令行在macOS上发送用户通知。 - 我爱学习网](https://www.5axxw.com/wiki/content/teoeri)


    # 打印当前系统时间  
    date  
    echo "The End."  
}  

# 执行入口 
# 进入脚本目录位置
#cd `dirname $0`
# 获取当前脚本目录位置
shellfilepath=`pwd`'/'$0
# 打印脚本目录地址
echo "[INFO]: 脚本地址 "${shellfilepath}

if true  
# if false  
then  
    echo "[Debug] true"
    # 开始执行  从标准输入中读取并同时写入到标准输出和指定的文件上 
    ## 拼接日志文件地址
    #logfilepath=`pwd`'/'$0'.log'
    #logfilepath=`pwd`'/'$0'-'$(date +%Y%m%d)'.log'
    logfilepath=$0'-'$(date +%Y%m%d)'.log'
    #logfilepath=`pwd`'/'$0'-'$(date +%y%m%d-%H-%M-%S)'.log'
    ## 打印日志文件地址
    echo "[INFO]: 日志地址" ${logfilepath}
    processControlMain  | tee -a ${logfilepath}
else  
    echo "[Debug] false"  
    ## 函数单元测试  
    #  
fi  

# 脚本结束  

